package com.qianyucc.blog.model.vo;

import cn.hutool.core.date.*;
import com.qianyucc.blog.exception.*;
import com.qianyucc.blog.model.enums.*;
import lombok.*;

import static com.qianyucc.blog.global.Constants.DATE_TIME_PATTERN;

/**
 * @author lijing
 * @date 2019-10-12 10:40
 * @description 封装向前端返回的结果
 */
@Data
@AllArgsConstructor
public class ResultVO {
    private Long code;
    private String msg;
    private String timestamp;

    public static ResultVO ok(String msg) {
        return new ResultVO(RespCode.SUCCESS.getCode(), msg, DateTime.now().toString(DATE_TIME_PATTERN));
    }

    public static ResultVO error(String msg, RespCode respCode) {
        return new ResultVO(respCode.getCode(), msg, DateTime.now().toString(DATE_TIME_PATTERN));
    }

    public static ResultVO error(BaseException e) {
        return new ResultVO(e.getCode(), e.getMessage(), DateTime.now().toString(DATE_TIME_PATTERN));
    }

    public static ResultVO error(String msg) {
        return new ResultVO(RespCode.UNKNOWN_ERROR.getCode(), msg, DateTime.now().toString(DATE_TIME_PATTERN));
    }
}

